import request from '../utils/request';

// 供应商管理相关API
export const supplierApi = {
  // 获取供应商列表
  getSupplierList: (params) => {
    return request.get('/api/suppliers', { params });
  },

  // 获取供应商详情
  getSupplierDetail: (id) => {
    return request.get(`/api/suppliers/${id}`);
  },

  // 创建供应商
  createSupplier: (data) => {
    return request.post('/api/suppliers', data);
  },

  // 更新供应商
  updateSupplier: (id, data) => {
    return request.put(`/api/suppliers/${id}`, data);
  },

  // 删除供应商
  deleteSupplier: (id) => {
    return request.delete(`/api/suppliers/${id}`);
  },

  // 获取供应商分类
  getSupplierCategories: () => {
    return request.get('/api/suppliers/categories');
  },

  // 创建供应商分类
  createSupplierCategory: (data) => {
    return request.post('/api/suppliers/categories', data);
  },

  // 更新供应商分类
  updateSupplierCategory: (id, data) => {
    return request.put(`/api/suppliers/categories/${id}`, data);
  },

  // 删除供应商分类
  deleteSupplierCategory: (id) => {
    return request.delete(`/api/suppliers/categories/${id}`);
  },

  // 获取供应商评价
  getSupplierRating: (supplierId) => {
    return request.get(`/api/suppliers/${supplierId}/rating`);
  },

  // 评价供应商
  rateSupplier: (supplierId, data) => {
    return request.post(`/api/suppliers/${supplierId}/rating`, data);
  },

  // 获取供应商合同
  getSupplierContracts: (supplierId, params) => {
    return request.get(`/api/suppliers/${supplierId}/contracts`, { params });
  },

  // 创建供应商合同
  createSupplierContract: (supplierId, data) => {
    return request.post(`/api/suppliers/${supplierId}/contracts`, data);
  },

  // 更新供应商合同
  updateSupplierContract: (supplierId, contractId, data) => {
    return request.put(`/api/suppliers/${supplierId}/contracts/${contractId}`, data);
  },

  // 删除供应商合同
  deleteSupplierContract: (supplierId, contractId) => {
    return request.delete(`/api/suppliers/${supplierId}/contracts/${contractId}`);
  },

  // 获取供应商统计
  getSupplierStatistics: (params) => {
    return request.get('/api/suppliers/statistics', { params });
  },

  // 供应商认证
  certifySupplier: (id, data) => {
    return request.post(`/api/suppliers/${id}/certify`, data);
  },

  // 取消供应商认证
  decertifySupplier: (id, data) => {
    return request.post(`/api/suppliers/${id}/decertify`, data);
  },

  // 获取供应商黑名单
  getSupplierBlacklist: (params) => {
    return request.get('/api/suppliers/blacklist', { params });
  },

  // 加入黑名单
  addToBlacklist: (id, data) => {
    return request.post(`/api/suppliers/${id}/blacklist`, data);
  },

  // 移出黑名单
  removeFromBlacklist: (id) => {
    return request.delete(`/api/suppliers/${id}/blacklist`);
  }
};
